<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  String basePath = request.getContextPath();
  Object email = request.getSession().getAttribute("email");
%>
<html>
<head>
  <title>小伙伴</title>
  <jsp:include page="../common/common-css.jsp"></jsp:include>
  <jsp:include page="../common/common-js.jsp"></jsp:include>
  <style type="text/css">
    a {
      text-decoration: none
    }

    a:hover {
      text-decoration: none
    }

    a:link {
      text-decoration: none
    }

    a:visited {
      text-decoration: none
    }
  </style>
</head>
<body style="padding: 0px;margin: 0px;background-color: #F5F5F5">
<jsp:include page="../../head.jsp"></jsp:include>
<div class="container-fluid"style="padding: 0px">
  <div class="col-xs-0 col-sm-0 col-md-3 col-lg-4"></div>
  <div class="col-xs-12 col-sm-12 col-md-6 col-lg-4" style="background-color: #ffffff;margin: 15px 0px;padding: 0px;">
    <div id="head" style="display: none">
      <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" align="center" style="margin: 20px 0px;">
        <img src="" style="width: 120px;height: 120px" alt="壕" id="champion" class="img-responsive img-circle">
      </div>
      <div id="mySort"></div>
      <table style="width: 100%;">
        <tr>
          <td style="width: 30%">
            <hr>
          </td>
          <td style="width: 40%" align="center">收益榜TOP.10</td>
          <td style="width: 30%">
            <hr>
          </td>
        </tr>
      </table>
    </div>
    <div id="usersArea">
      <table style="width: 100%;background-color: #ffffff">
        <tr>
          <td align="center" style="color: #d3d3d3;padding: 100px 0px;"><i class="icon-spinner icon-spin text-default-color"></i>&nbsp;正在加载数据......
          </td>
        </tr>
      </table>
    </div>
    <div id="users"></div>
    <table style="width: 100%;display: none;" id="loadMore">
      <tr>
        <td align="center" class="load" style="color: darkgrey;padding: 40px">加载更多</td>
      </tr>
    </table>
    <table style="width: 100%;display: none;" id="loadOver">
      <tr>
        <td align="center" class="load" style="color: darkgrey;padding: 40px 0px"></td>
      </tr>
    </table>
  </div>
</div>
<jsp:include page="../../foot.jsp"></jsp:include>
</body>
<script language="JavaScript">
  var pageNo = 1;
  function setChampion(name, logo) {
    if (logo == null || logo == '' || logo == undefined) {
      $("#champion").attr("src", "<%=basePath%>/img/user.png");
    } else {
      $("#champion").attr("src", logo + "-120x120");
    }
  }
  function loadUser(pageNo, pageSize) {
    var url = "<%=basePath%>/user/list";
    var param = {pageNo: pageNo, pageSize: pageSize};
    $.post(url, param, function (data, status) {
      var users = data.paginator.items;
      var user = data.shCompany;
      $("#usersArea").hide();
      var item;
      var subItem;
      var logo;
      var alias;
      if (users != null && users.length > 0) {
        if (pageNo == 1) {
          $("#head").show();
          // - 设置最佳硬汉封面
          setChampion(users[0].name, users[0].logo);
        }
        for (var i = 0; i < users.length; i++) {
          logo = "<%=basePath%>/img/user.png"
          if (users[i].logo != null && users[i].logo != '' && users[i].logo != undefined) {
            logo = users[i].logo + "-120x120";
          }
          alias = users[i].name;
          if (users[i].name == '' || users[i].name == null) {
            alias = users[i].email;
          }
          subItem = "";
          item = "";
          item += '<a href="<%=basePath%>/user/queryinfo?email=' + users[i].email + '">';
          item += '<table style="width: 100%;margin-top: 5px;margin-bottom: 5px">';
          item += '<tr>';
          item += '<td align="center" style="width: 30px;">' + sort + '</td>';
          item += '<td style="padding: 5px;width: 55px"align="center"><img style="width: 40px;height: 40px" class="img-responsive img-circle" src="' + logo + '"></td>';
          item += '<td style="padding: 5px;border-bottom: 1px solid #f5f5f5;font-size: small">' + alias + '</td>';
          item += '<td style="padding: 5px 20px 5px 5px;border-bottom: 1px solid #f5f5f5;color: gray"align="right">￥<span style="font-size: large" class="text-default-color">' + users[i].inCount + '</span></td>';
          item += '</tr>';
          item += '</table>';
          item += '</a>';
          sort++;
          $("#users").append(item);
        }
        if (users.length == pageSize) {
          // - 还有更多数据
          $("#loadOver").hide();
          $("#loadMore").show();
        } else {
          // - 没有更多数据
          $("#loadMore").hide();
          $("#loadOver").show();
        }
      } else {
        if (pageNo == 1) {
          // - 没有数据
          var noDataShow = '';
          noDataShow += '<div style="padding: 100px 0px;background-color: #f5f5f5" class="text-center">';
          noDataShow += '<h3 style="color: #cccccc">All user will be Here</h3>';
          noDataShow += '</div>';
          $("#users").empty();
          $("#users").append(noDataShow);
        }
      }
    })
  }
  var sort = 1;
  $(document).ready(function () {
    initStyle();
    loadUser(pageNo++, 10);
    $("#loadMore").click(function () {
      loadUser(pageNo++, 10);
    })
  })
</script>
</html>
